if __name__ == '__main__':
    lst = ["衣服","鞋子","书包","裤子","电脑"]

    cart = []
    while True:
        flag = False
        num = str(input("输入需要购买的商品:"))
        for item in lst:
            if num == item:
                flag = True
                cart.append(item)
                break
        if not flag and num != 'q':  # flag==False 简写写法 not flag
            print('该商品不存在!')
        if num == 'q':
            break
    cart.reverse()
    for item in cart:
        print(item)